package com.lishe.lishe.lishe.module.excitation.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.StyleRes;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;

import com.lishe.lishe.R;
import com.lishe.lishe.lishe.module.excitation.bean.AchievementObject;

/**
 * Created by DELL on 2017/10/30.
 */

public class AchievementGetSuccessDialog extends Dialog {


    public AchievementGetSuccessDialog(@NonNull Context context, @StyleRes int themeResId) {
        super(context, themeResId);
    }

    public static class Builder implements View.OnClickListener {
        private Context context;
        private AchievementObject achievement;
        private AchievementGetSuccessDialog dialog;

        public Builder(Context context){
            this.context=context;
        }

        public Builder setAchievementObject(AchievementObject achievement){
            this.achievement=achievement;
            return this;
        }


        public AchievementGetSuccessDialog create(){
            if(dialog==null) {
                dialog = new AchievementGetSuccessDialog(context, R.style.MyDialog);
                View contentView = LayoutInflater.from(context).inflate(R.layout.dialog_ahievement_get_success, null);
                Button sure=contentView.findViewById(R.id.sure);

                sure.setOnClickListener(this);
                contentView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog.dismiss();
                        dialog.cancel();
                    }
                });

                dialog.setContentView(contentView);
                dialog.getWindow().setGravity(Gravity.CENTER);
                dialog.setCanceledOnTouchOutside(true);
                dialog.setCancelable(true);
                WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
                lp.width = WindowManager.LayoutParams.MATCH_PARENT;
                lp.height = WindowManager.LayoutParams.MATCH_PARENT;
                dialog.getWindow().setAttributes(lp);
            }
            return dialog;
        }

        public void show(){
            create();
            if(dialog!=null&&!dialog.isShowing()){
                dialog.show();
            }
        }

        public void dissmiss(){
            dialog.dismiss();
            dialog.cancel();
        }

        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.dissmiss:
                case R.id.sure:
                    dissmiss();
                    break;
            }
        }
    }

}
